From 10128bdb23b42d84545c29c5e6864463183fd9b4 Mon Sep 17 00:00:00 2001 From: Ian Campbell Date: Thu, 17 Mar 2011 19:15:18 +0000 Subject: [PATCH] tools: link each shared library or binary only against the libraries it uses In particular if binary A uses libB and libB uses libC entirely internally then A does not need to link against libC only libB. However when linking binary A the linker does need to have visibility of the libraries which libB links against (libC in this example). For out of tree uses this is achieved without fuss due because the libraries are installed in a standard path. However in the case of in-tree users the linker needs a hint in the form of the -rpath-link option. Therefore a new class of build variable, $(SHLIB_FOO), is introduced which includes the linker options needed to link against a library which uses libFOO. The intention is that $(LDLIBS_bar) will include the $(SHLIB_foo)s which it uses where necessary rather requiring that users are aware of this. For the python extensions this change appears particularly large since previously each of python bindings were linked against the union of all possible libraries used by all bindings instead of just what they individually needed. This change removes a dependency on libdl.so from nearly everything in the system, only libxenctrl actually uses it. In the context of xl/libxl the intention of libxl is to remove any need for a user of libxl to know about libxenstore or libxenctrl, however in the current build it is xl which links against those libraries rather than libxl (which only links against libc). After this change libxl correctly depends on the libraries it uses and xl does not depend on libraries which it is not support to be required to know about. Note that xl does depend on libxenctrl.so since it uses xtl_* directly. Signed-off-by: Ian Campbell Committed-by: Ian Jackson --- tools/Rules.mk | 12 ++- tools/blktap2/drivers/Makefile | 4 - tools/blktap2/vhd/Makefile | 3 - tools/libxl/Makefile | 16 ++-- tools/python/setup.py | 134 +++++++++++++----------------- tools/python/xen/lowlevel/xl/xl.c | 1 - tools/python/xen/lowlevel/xs/xs.c | 1 - 7 files changed, 78 insertions(+), 93 deletions(-) diff --git a/tools/Rules.mk b/tools/Rules.mk index f7dda356b5..6249573c5b 100644 --- a/tools/Rules.mk +++ b/tools/Rules.mk @@ -11,6 +11,7 @@ INSTALL = $(XEN_ROOT)/tools/cross-install XEN_INCLUDE = $(XEN_ROOT)/tools/include XEN_XC = $(XEN_ROOT)/tools/python/xen/lowlevel/xc XEN_LIBXC = $(XEN_ROOT)/tools/libxc +XEN_XENLIGHT = $(XEN_ROOT)/tools/libxl XEN_XENSTORE = $(XEN_ROOT)/tools/xenstore XEN_LIBXENSTAT = $(XEN_ROOT)/tools/xenstat/libxenstat/src XEN_BLKTAP2 = $(XEN_ROOT)/tools/blktap2 @@ -18,13 +19,16 @@ XEN_BLKTAP2 = $(XEN_ROOT)/tools/blktap2 CFLAGS_include = -I$(XEN_INCLUDE) CFLAGS_libxenctrl = -I$(XEN_LIBXC) $(CFLAGS_include) -LDLIBS_libxenctrl = -L$(XEN_LIBXC) -lxenctrl $(DLOPEN_LIBS) +LDLIBS_libxenctrl = -L$(XEN_LIBXC) -lxenctrl +SHLIB_libxenctrl = -Wl,-rpath-link=$(XEN_LIBXC) CFLAGS_libxenguest = -I$(XEN_LIBXC) $(CFLAGS_include) LDLIBS_libxenguest = -L$(XEN_LIBXC) -lxenguest +SHLIB_libxenguest = -Wl,-rpath-link=L$(XEN_LIBXC) CFLAGS_libxenstore = -I$(XEN_XENSTORE) $(CFLAGS_include) LDLIBS_libxenstore = -L$(XEN_XENSTORE) -lxenstore +SHLIB_libxenstore = -Wl,-rpath-link=$(XEN_XENSTORE) ifeq ($(CONFIG_Linux),y) LIBXL_BLKTAP = y @@ -35,11 +39,17 @@ endif ifeq ($(LIBXL_BLKTAP),y) CFLAGS_libblktapctl = -I$(XEN_BLKTAP2)/control -I$(XEN_BLKTAP2)/include $(CFLAGS_include) LDLIBS_libblktapctl = -L$(XEN_BLKTAP2)/control -lblktapctl +SHLIB_libblktapctl = -Wl,-rpath-link=$(XEN_BLKTAP2)/control else CFLAGS_libblktapctl = LDLIBS_libblktapctl = +SHLIB_libblktapctl = endif +CFLAGS_libxenlight = -I$(XEN_XENLIGHT) $(CFLAGS_include) +LDLIBS_libxenlight = -L$(XEN_XENLIGHT) $(SHLIB_libxenctrl) $(SHLIB_libxenstore) $(SHLIB_libblktapctl) -lxenlight +SHLIB_libxenlight = -Wl,-rpath-link=$(XEN_XENLIGHT) + X11_LDPATH = -L/usr/X11R6/$(LIBLEAFDIR) CFLAGS += -D__XEN_TOOLS__ diff --git a/tools/blktap2/drivers/Makefile b/tools/blktap2/drivers/Makefile index b718c0839f..33a33d3606 100644 --- a/tools/blktap2/drivers/Makefile +++ b/tools/blktap2/drivers/Makefile @@ -29,10 +29,6 @@ LBLIBS_img := $(LDLIBS_libxenctrl) $(CRYPT_LIB) -lpthread -lz -lm LIBS += -L$(LIBVHDDIR) -lvhd -ifeq ($(CONFIG_Linux),y) -LIBS += -luuid -endif - REMUS-OBJS := block-remus.o REMUS-OBJS += hashtable.o REMUS-OBJS += hashtable_itr.o diff --git a/tools/blktap2/vhd/Makefile b/tools/blktap2/vhd/Makefile index cb5e14593d..1dcf9a5492 100644 --- a/tools/blktap2/vhd/Makefile +++ b/tools/blktap2/vhd/Makefile @@ -22,9 +22,6 @@ CFLAGS += -static endif LIBS := -Llib -lvhd -ifeq ($(CONFIG_Linux),y) -LIBS += -luuid -endif # Get gcc to generate the dependencies for us. CFLAGS += -Wp,-MD,.$(@F).d diff --git a/tools/libxl/Makefile b/tools/libxl/Makefile index 725d5d1491..62020ed31b 100644 --- a/tools/libxl/Makefile +++ b/tools/libxl/Makefile @@ -15,11 +15,17 @@ CFLAGS += -Werror -Wno-format-zero-length -Wmissing-declarations CFLAGS += -I. -fPIC CFLAGS += $(CFLAGS_libxenctrl) $(CFLAGS_libxenguest) $(CFLAGS_libxenstore) $(CFLAGS_libblktapctl) -LIBS = $(LDLIBS_libxenctrl) $(LDLIBS_libxenguest) $(LDLIBS_libxenstore) $(LDLIBS_libblktapctl) $(UTIL_LIBS) ifeq ($(CONFIG_Linux),y) -LIBS += -luuid +LIBUUID_LIBS += -luuid endif +LIBXL_LIBS = +LIBXL_LIBS = $(LDLIBS_libxenctrl) $(LDLIBS_libxenguest) $(LDLIBS_libxenstore) $(LDLIBS_libblktapctl) $(UTIL_LIBS) $(LIBUUID_LIBS) + +LIBXLU_LIBS = + +CLIENT_LIBS = $(LDLIBS_libxenlight) + LIBXL_OBJS-y = osdeps.o libxl_paths.o libxl_bootloader.o flexarray.o ifeq ($(LIBXL_BLKTAP),y) LIBXL_OBJS-y += libxl_blktap2.o @@ -81,7 +87,7 @@ libxenlight.so.$(MAJOR): libxenlight.so.$(MAJOR).$(MINOR) ln -sf $< $@ libxenlight.so.$(MAJOR).$(MINOR): $(LIBXL_OBJS) - $(CC) $(CFLAGS) $(LDFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,libxenlight.so.$(MAJOR) $(SHLIB_LDFLAGS) -o $@ $^ + $(CC) $(CFLAGS) -Wl,-rpath-link -Wl,$(XEN_ROOT)/tools/libxc $(LDFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,libxenlight.so.$(MAJOR) $(SHLIB_LDFLAGS) -o $@ $^ $(LIBXL_LIBS) libxenlight.a: $(LIBXL_OBJS) $(AR) rcs libxenlight.a $^ @@ -93,13 +99,13 @@ libxlutil.so.$(XLUMAJOR): libxlutil.so.$(XLUMAJOR).$(XLUMINOR) ln -sf $< $@ libxlutil.so.$(XLUMAJOR).$(XLUMINOR): $(LIBXLU_OBJS) - $(CC) $(CFLAGS) $(LDFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,libxlutil.so.$(XLUMAJOR) $(SHLIB_LDFLAGS) -o $@ $^ + $(CC) $(CFLAGS) $(LDFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,libxlutil.so.$(XLUMAJOR) $(SHLIB_LDFLAGS) -o $@ $^ $(LIBXLU_LIBS) libxlutil.a: $(LIBXLU_OBJS) $(AR) rcs libxlutil.a $^ $(CLIENTS): $(XL_OBJS) libxlutil.so libxenlight.so - $(CC) $(LDFLAGS) -o $@ $^ $(LIBS) + $(CC) $(LDFLAGS) -o $@ $(XL_OBJS) libxlutil.so libxenlight.so $(CLIENT_LIBS) .PHONY: install install: all diff --git a/tools/python/setup.py b/tools/python/setup.py index 28c4d85e67..f803632d3b 100644 --- a/tools/python/setup.py +++ b/tools/python/setup.py @@ -6,119 +6,98 @@ XEN_ROOT = "../.." extra_compile_args = [ "-fno-strict-aliasing", "-Werror" ] -include_dirs = [ XEN_ROOT + "/tools/libxc", - XEN_ROOT + "/tools/xenstore", - XEN_ROOT + "/tools/include", - XEN_ROOT + "/tools/libxl", - ] - -library_dirs = [ XEN_ROOT + "/tools/libxc", - XEN_ROOT + "/tools/xenstore", - XEN_ROOT + "/tools/libxl" - ] - -libraries = [ "xenctrl", "xenguest", "xenstore" ] - -depends = [ XEN_ROOT + "/tools/libxc/libxenctrl.so", - XEN_ROOT + "/tools/libxc/libxenguest.so", - XEN_ROOT + "/tools/xenstore/libxenstore.so" - ] - -plat = os.uname()[0] -if plat == 'Linux': - uuid_libs = ["uuid"] - blktap_ctl_libs = ["blktapctl"] - library_dirs.append(XEN_ROOT + "/tools/blktap2/control") - blktab_ctl_depends = [ XEN_ROOT + "/tools/blktap2/control/libblktapctl.so" ] -else: - uuid_libs = [] - blktap_ctl_libs = [] - blktab_ctl_depends = [] +PATH_XEN = XEN_ROOT + "/tools/include" +PATH_LIBXC = XEN_ROOT + "/tools/libxc" +PATH_LIBXL = XEN_ROOT + "/tools/libxl" +PATH_XENSTORE = XEN_ROOT + "/tools/xenstore" xc = Extension("xc", extra_compile_args = extra_compile_args, - include_dirs = include_dirs + [ "xen/lowlevel/xc" ], - library_dirs = library_dirs, - libraries = libraries, - depends = depends, + include_dirs = [ PATH_XEN, PATH_LIBXC, "xen/lowlevel/xc" ], + library_dirs = [ PATH_LIBXC ], + libraries = [ "xenctrl", "xenguest" ], + depends = [ PATH_LIBXC + "/libxenctrl.so", PATH_LIBXC + "/libxenguest.so" ], sources = [ "xen/lowlevel/xc/xc.c" ]) xs = Extension("xs", extra_compile_args = extra_compile_args, - include_dirs = include_dirs + [ "xen/lowlevel/xs" ], - library_dirs = library_dirs, - libraries = libraries, - depends = depends, + include_dirs = [ PATH_XEN, PATH_XENSTORE, "xen/lowlevel/xs" ], + library_dirs = [ PATH_XENSTORE ], + libraries = [ "xenstore" ], + depends = [ PATH_XENSTORE + "/libxenstore.so" ], sources = [ "xen/lowlevel/xs/xs.c" ]) scf = Extension("scf", extra_compile_args = extra_compile_args, - include_dirs = include_dirs + [ "xen/lowlevel/scf" ], - library_dirs = library_dirs, - libraries = libraries, - depends = depends, + include_dirs = [ "xen/lowlevel/scf" ], + library_dirs = [ ], + libraries = [ ], + depends = [ ], sources = [ "xen/lowlevel/scf/scf.c" ]) - + process = Extension("process", extra_compile_args = extra_compile_args, - include_dirs = include_dirs + [ "xen/lowlevel/process" ], - library_dirs = library_dirs, - libraries = libraries + [ "contract" ], - depends = depends, + include_dirs = [ "xen/lowlevel/process" ], + library_dirs = [ ], + libraries = [ "contract" ], + depends = [ ], sources = [ "xen/lowlevel/process/process.c" ]) acm = Extension("acm", extra_compile_args = extra_compile_args, - include_dirs = include_dirs + [ "xen/lowlevel/acm" ], - library_dirs = library_dirs, - libraries = libraries, - depends = depends, + include_dirs = [ PATH_XEN, PATH_LIBXC, "xen/lowlevel/acm" ], + library_dirs = [ PATH_LIBXC ], + libraries = [ "xenctrl" ], + depends = [ PATH_LIBXC + "/libxenctrl.so" ], sources = [ "xen/lowlevel/acm/acm.c" ]) flask = Extension("flask", extra_compile_args = extra_compile_args, - include_dirs = include_dirs + [ "xen/lowlevel/flask" ] + - [ "../flask/libflask/include" ], - library_dirs = library_dirs + [ "../flask/libflask" ], - libraries = libraries + [ "flask" ], - depends = depends + [ XEN_ROOT + "/tools/flask/libflask/libflask.so" ], + include_dirs = [ PATH_XEN, PATH_LIBXC, "xen/lowlevel/flask", + "../flask/libflask/include" ], + library_dirs = [ PATH_LIBXC, "../flask/libflask" ], + libraries = [ "xenctrl", "flask" ], + depends = [ PATH_LIBXC + "/libxenctrl.so", + XEN_ROOT + "/tools/flask/libflask/libflask.so" ], sources = [ "xen/lowlevel/flask/flask.c" ]) ptsname = Extension("ptsname", extra_compile_args = extra_compile_args, - include_dirs = include_dirs + [ "ptsname" ], - library_dirs = library_dirs, - libraries = libraries, - depends = depends, + include_dirs = [ "ptsname" ], + library_dirs = [ ], + libraries = [ ], + depends = [ ], sources = [ "ptsname/ptsname.c" ]) checkpoint = Extension("checkpoint", - extra_compile_args = extra_compile_args, - include_dirs = include_dirs, - library_dirs = library_dirs, - libraries = libraries + [ "rt" ], - depends = depends, - sources = [ "xen/lowlevel/checkpoint/checkpoint.c", - "xen/lowlevel/checkpoint/libcheckpoint.c"]) + extra_compile_args = extra_compile_args, + include_dirs = [ PATH_XEN, PATH_LIBXC, PATH_XENSTORE ], + library_dirs = [ PATH_LIBXC, PATH_XENSTORE ], + libraries = [ "xenctrl", "xenguest", "xenstore", "rt" ], + depends = [ PATH_LIBXC + "/libxenctrl.so", + PATH_LIBXC + "/libxenguest.so", + PATH_XENSTORE + "/libxenstore.so" ], + sources = [ "xen/lowlevel/checkpoint/checkpoint.c", + "xen/lowlevel/checkpoint/libcheckpoint.c"]) netlink = Extension("netlink", - extra_compile_args = extra_compile_args, - include_dirs = include_dirs, - library_dirs = library_dirs, - libraries = libraries, - depends = depends, - sources = [ "xen/lowlevel/netlink/netlink.c", - "xen/lowlevel/netlink/libnetlink.c"]) + extra_compile_args = extra_compile_args, + include_dirs = [ ], + library_dirs = [ ], + libraries = [ ], + depends = [ ], + sources = [ "xen/lowlevel/netlink/netlink.c", + "xen/lowlevel/netlink/libnetlink.c"]) xl = Extension("xl", extra_compile_args = extra_compile_args, - include_dirs = include_dirs + [ "xen/lowlevel/xl" ], - library_dirs = library_dirs, - libraries = libraries + ["xenlight" ] + blktap_ctl_libs + uuid_libs, - depends = depends + blktab_ctl_depends + - [ XEN_ROOT + "/tools/libxl/libxenlight.so" ], + include_dirs = [ PATH_XEN, PATH_LIBXL, PATH_LIBXC, PATH_XENSTORE, "xen/lowlevel/xl" ], + library_dirs = [ PATH_LIBXL ], + libraries = [ "xenlight" ], + depends = [ PATH_LIBXL + "/libxenlight.so" ], sources = [ "xen/lowlevel/xl/xl.c", "xen/lowlevel/xl/_pyxl_types.c" ]) +plat = os.uname()[0] modules = [ xc, xs, ptsname, acm, flask, xl ] if plat == 'SunOS': modules.extend([ scf, process ]) @@ -143,7 +122,6 @@ setup(name = 'xen', 'xen.sv', 'xen.xsview', 'xen.remus', - 'xen.xend.tests', 'xen.xend.server.tests', 'xen.xend.xenstore.tests', diff --git a/tools/python/xen/lowlevel/xl/xl.c b/tools/python/xen/lowlevel/xl/xl.c index 14ad809f0f..07c29d4a25 100644 --- a/tools/python/xen/lowlevel/xl/xl.c +++ b/tools/python/xen/lowlevel/xl/xl.c @@ -35,7 +35,6 @@ #include #include #include -#include #include #include diff --git a/tools/python/xen/lowlevel/xs/xs.c b/tools/python/xen/lowlevel/xs/xs.c index 7f28aa291a..76a00a42a2 100644 --- a/tools/python/xen/lowlevel/xs/xs.c +++ b/tools/python/xen/lowlevel/xs/xs.c @@ -30,7 +30,6 @@ #include #include -#include #include "xs.h" /** @file -- 2.30.2